package com.gitee.fanx.rpc.dto;

import java.util.List;
import java.util.StringJoiner;

/**
 * 内部通讯分页返回结果
 *
 * @param <T>
 * @author 凡行
 */
public class PageResponse<T> {
    /**
     * 当前页码数（默认给1）
     */
    private Integer pageNum = 1;
    /**
     * 每页显示的行数（默认给10）
     */
    private Integer pageSize = 10;
    /**
     * 总数据量
     */
    private Long total;
    /**
     * 总页数
     */
    private int pages;
    /**
     * 结果集
     */
    private List<T> list;

    public PageResponse() {
    }

    public PageResponse(Integer pageNum, Integer pageSize, long total, Integer pages, List<T> dataList) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.pages = pages;
        this.list = dataList;
    }

    public PageResponse(PageResponse<?> pageInfo, List<T> dataList) {
        this(pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getTotal(), pageInfo.getPages(), dataList);
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", PageResponse.class.getSimpleName() + "[", "]")
            .add("pageNum=" + pageNum)
            .add("pageSize=" + pageSize)
            .add("total=" + total)
            .add("pages=" + pages)
            .add("list=" + list.size())
            .toString();
    }
}
